<template>
  <el-dialog
    :title="!dataForm.donationInformationId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="申请人id" prop="applicationId">
      <el-input v-model="dataForm.applicationId" placeholder="申请人id"></el-input>
    </el-form-item>
    <el-form-item label="学段" prop="learningSection">
      <el-input v-model="dataForm.learningSection" placeholder="学段"></el-input>
    </el-form-item>
    <el-form-item label="就读学校" prop="learningSchool">
      <el-input v-model="dataForm.learningSchool" placeholder="就读学校"></el-input>
    </el-form-item>
    <el-form-item label="受助人信息" prop="name">
      <el-input v-model="dataForm.name" placeholder="受助人信息"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="cardId">
      <el-input v-model="dataForm.cardId" placeholder="身份证号"></el-input>
    </el-form-item>
    <el-form-item label="收款账号" prop="account">
      <el-input v-model="dataForm.account" placeholder="收款账号"></el-input>
    </el-form-item>
    <el-form-item label="收款地址" prop="receivingAddress">
      <el-input v-model="dataForm.receivingAddress" placeholder="收款地址"></el-input>
    </el-form-item>
    <el-form-item label="目标金额" prop="targetAmount">
      <el-input v-model="dataForm.targetAmount" placeholder="目标金额"></el-input>
    </el-form-item>
    <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="deleteTime">
      <el-input v-model="dataForm.deleteTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="0为未审核状态，1为审核通过状态，2为审核否决状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="0为未审核状态，1为审核通过状态，2为审核否决状态"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          donationInformationId: 0,
          applicationId: '',
          learningSection: '',
          learningSchool: '',
          name: '',
          cardId: '',
          account: '',
          receivingAddress: '',
          targetAmount: '',
          createTime: '',
          updateTime: '',
          deleteTime: '',
          status: ''
        },
        dataRule: {
          applicationId: [
            { required: true, message: '申请人id不能为空', trigger: 'blur' }
          ],
          learningSection: [
            { required: true, message: '学段不能为空', trigger: 'blur' }
          ],
          learningSchool: [
            { required: true, message: '就读学校不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '受助人信息不能为空', trigger: 'blur' }
          ],
          cardId: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          account: [
            { required: true, message: '收款账号不能为空', trigger: 'blur' }
          ],
          receivingAddress: [
            { required: true, message: '收款地址不能为空', trigger: 'blur' }
          ],
          targetAmount: [
            { required: true, message: '目标金额不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          deleteTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '0为未审核状态，1为审核通过状态，2为审核否决状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.donationInformationId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.donationInformationId) {
            this.$http({
              url: this.$http.adornUrl(`/donation/auditdonationpublic/info/${this.dataForm.donationInformationId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.applicationId = data.auditDonationPublic.applicationId
                this.dataForm.learningSection = data.auditDonationPublic.learningSection
                this.dataForm.learningSchool = data.auditDonationPublic.learningSchool
                this.dataForm.name = data.auditDonationPublic.name
                this.dataForm.cardId = data.auditDonationPublic.cardId
                this.dataForm.account = data.auditDonationPublic.account
                this.dataForm.receivingAddress = data.auditDonationPublic.receivingAddress
                this.dataForm.targetAmount = data.auditDonationPublic.targetAmount
                this.dataForm.createTime = data.auditDonationPublic.createTime
                this.dataForm.updateTime = data.auditDonationPublic.updateTime
                this.dataForm.deleteTime = data.auditDonationPublic.deleteTime
                this.dataForm.status = data.auditDonationPublic.status
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/donation/auditdonationpublic/${!this.dataForm.donationInformationId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'donationInformationId': this.dataForm.donationInformationId || undefined,
                'applicationId': this.dataForm.applicationId,
                'learningSection': this.dataForm.learningSection,
                'learningSchool': this.dataForm.learningSchool,
                'name': this.dataForm.name,
                'cardId': this.dataForm.cardId,
                'account': this.dataForm.account,
                'receivingAddress': this.dataForm.receivingAddress,
                'targetAmount': this.dataForm.targetAmount,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'deleteTime': this.dataForm.deleteTime,
                'status': this.dataForm.status
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
